/*
 =============================================================================
 FILE...............: BookingManagementService.java
 COMMENTS...........: Represents a flight booking management system.
 =============================================================================
 AUTHOR(S)..........: Everton Ranielly de Sousa Cavalcante
 					  Department of Informatics and Applied Mathematics
 					  Federal University of Rio Grande do Norte
 LAST MODIFICATION..: November 26th, 2012
 ============================================================================= 					  
*/


/* ========================================================================= */
/* PACKAGES							                                         */
/* ------------------------------------------------------------------------- */
package services;


/* ========================================================================= */
/* IMPORTS							                                         */
/* ------------------------------------------------------------------------- */
import model.Booking;
import model.Client;
import model.Flight;


/* ========================================================================= */
/* CLASS BookingManagementService                                            */
/* ------------------------------------------------------------------------- */
/**
 * Represents a flight booking management system
 * @author Everton Cavalcante
 */
public class BookingManagementService 
{
	/**
	 * Selects the departure and return flights among the available ones
	 * @param availableFlights Available flights
	 * @return Selected flights (departure and return ones)
	 */
	public Flight[] selectFlights(Flight[] availableFlights) 
	{
		// FIXME Implement this method
		return availableFlights;
	}
	
	
	/**
	 * Generates a booking based on the selected flights and the client information
	 * @param sflights Selected flights
	 * @param client Client
	 * @return Generated booking
	 */
	public Booking generateBooking(Flight[] selectedFlights, Client client) 
	{ 
		// Generated booking		
		Booking booking = new Booking(selectedFlights[0], selectedFlights[1], client);
		
		// Generates a random 8-letter (upper-cased) booking code
		char[] bookingChar = new char[8];
		for (int i = 0; i < 8; i++)
			bookingChar[i] = (char)(65 + (int)(25 * Math.random()));	// Random integer between 65 (A) and 90 (Z)
		booking.setBookingCode(new String(bookingChar));
		
		/* FIXME It is necessary to handle the selected flight class and respective value to be paid 
		 * (since the value depends on the chosen class) and additional information */
		return booking;
	}
}